<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('工单表列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>创建人：</label>
                            <input type="text" name="createUser"/>
                        </li>
                        <li>
                            <label>持有者：</label>
                            <input type="text" name="holdUser"/>
                        </li>
                        <li>
                            <label>工单状态：</label>
                            <select name="workStatus">
                                <option value="">请选择</option>
                                <option value="0">新工单</option>
                                <option value="1">已处理</option>
                            </select>
                        </li>
                        <!--<li>
                            <label>完成描述：</label>
                            <input type="text" name="completeDescription"/>
                        </li>-->
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <!--<div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" href="/system/customer" shiro:hasPermission="system:form:add">
            <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="system:form:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="system:form:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:form:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>-->
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">

    var editFlag = [[${@permission.hasPermi('system:form:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:form:remove')}]];
    var prefix = ctx + "system/pend";
    var a;
    var b;
    var c;
    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "工单表",
            onDblClickRow:function(row,index,layero){
                layer.open({
                    type: 2,
                    area: ['500' + 'px', '400' + 'px'],
                    fix: false,
                    //不固定
                    maxmin: true,
                    shade: 0.3,
                    title: "查看信息",
                    content: prefix+"/checkData/"+row.id,
                    btn: ['确定', '关闭'],
                    // 弹层外区域关闭
                    shadeClose: true,
                    yes: function (index) {
                        layer.close(index);
                    },
                    cancel: function(index) {
                        return true;
                    }
                });
            },
            columns: [{
                checkbox: true

            },
                {
                    field: 'id',
                    title: 'id',
                    visible: false,

                },

                {
                    field: 'createUser',
                    title: '创建人'
                },
                {
                    field: 'holdUser',
                    title: '持有者'
                },
                {
                    field: 'custName',
                    title: '顾客姓名'
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    field: 'workStatus',
                    title: '工单状态',
                    formatter: function (value) {

                            if (value == '0') {
                                b = '1'
                                return '<div >新工单审核</div>'
                            } else {
                                b = '2'
                                return '<div >已处理</div>'
                        }
                    }
                },
                {
                    field: 'transferStatus',
                    title: '转移',
                    formatter: function (value) {
                        if(value=='0'){
                            c='1'
                            return '<div ></div>'
                        }else {
                            c='2'
                            return '<div >转移审核失败</div>'
                        }
                    }
                },
                {
                    field: 'returnStatus',
                    title: '审核状态',
                    formatter: function (value) {
                            if (value == '1') {
                                a = '1'
                                return '<div >新工单审核成功</div>'
                            } else {
                                a = '2'
                                if (b == '2') {
                                    return '<div >已处理审核失败</div>'
                                } else {
                                    return '<div >新工单审核失败</div>'
                                }
                            }
                    }
                },
                {
                    field: 'faultDescription',
                    title: '故障描述'
                },
                {
                    field: 'faultPhotoAddress',
                    title: '故障照片'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (a == '1'||c=='2') {
                            actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="finishForm(\'' + row.id + '\')"><i class="fa fa-edit"></i>工单处理</a> ');
                            if(b=='1') {
                                actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="transTo(\'' + row.id + '\')"><i class="fa fa-edit"></i>转移申请</a>');
                            }else {
                                actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="finishCheckForm(\'' + row.id + '\')"><i class="fa fa-edit"></i>提交申请</a>');
                            }
                        } else {
                            if(b=='1'){
                                actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="removeForm(\'' + row.id + '\')"><i class="fa fa-edit"></i>删除</a>');
                                actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="newForm(\'' + row.id + '\')"><i class="fa fa-edit"></i>从新编辑</a>');
                                actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="newCheckForm(\'' + row.id + '\')"><i class="fa fa-edit"></i>提交审核</a>');
                            }else {
                                actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="finishForm(\'' + row.id + '\')"><i class="fa fa-edit"></i>工单处理</a> ');
                                actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="finishCheckForm(\'' + row.id + '\')"><i class="fa fa-edit"></i>提交申请</a>');
                            }

                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function finishForm(id) {

        var title, url, width, height
        title = "工单完成处理",
            url = prefix + "/finishFrom/" + id,
            width = '500',
            height = '400'
        $.modal.openTab(title, url)
    };

    function newForm(id) {
        var title, url, width, height
        title = "重新编辑",
            url = prefix + "/newForm/" + id,
            width = '500',
            height = '400'
        $.modal.openTab(title, url)
    };
    function removeForm(id) {
        var title,url,width,height
        url=prefix+"/removeForm/"+id,
            width='500',
            height='400'
        $.modal.confirm("您确定删除", function() {
            $.operate.post(url)
        });
    };

    function newCheckForm(id) {
        var title,url,width,height
        url=prefix+"/newCheckForm/"+id,
            width='500',
            height='400'
        $.modal.confirm("提交新工单审核", function() {
            $.operate.post(url)
        });
    }

    function finishCheckForm(id) {
        var title,url,width,height
            url=prefix+"/finishCheckForm/"+id,
            width='500',
            height='400'
        $.modal.confirm("提交处理完成申请", function() {
            $.operate.post(url)
        });
    };
    function transTo(id) {
        var title,url,width,height
        title="转移给",
            url=prefix+"/transto/"+id,
            width='500',
            height='400'
        $.modal.openTab(title,url)
    }

    function submitHandler(id) {
        $.modal.refresh()
    }
</script>
</body>
</html>
